import json

# 一口气全部读取出来
with open("C:\\Users\\ASUS\Desktop\\学习资料地址\\《Spring Security Oauth2.0认证授权专题》课程资料-免费.TXT") as allText:
    text = allText.read()
    print(text)


# 逐行取出
with open('C:\\Users\\ASUS\Desktop\\学习资料地址\\《Spring Security Oauth2.0认证授权专题》课程资料-免费.TXT') as lineText:
    count = 1
    for lline in lineText:
        print(f'{count}行为：{lline}')
        count+=1

# 读取创建文件
with open('C:\\Users\\ASUS\Desktop\\学习资料地址\\《Spring Security Oauth2.0认证授权专题》课程资料-免费.TXT') as readCreatText:
    readLine = readCreatText.readlines()
    print(readLine)
    for line in readLine:
        strp = line.rstrip()
        print(strp)

# 写入文件   如果文件不存在就自动生成
with open("C:\\Users\\ASUS\Desktop\\学习资料地址\\test.TXT",'w') as writTe:
    writTe.write(text)











# 写json到文件
list = [1,2,3,4,5]

with open("C:\\Users\\ASUS\Desktop\\学习资料地址\\test.TXT",'w') as writTe:
    jsonlist = json.dump(list,writTe)


# 从文件中读取数据  并且是list变为list
with open("C:\\Users\\ASUS\Desktop\\学习资料地址\\test.TXT") as jsonRead:
    print(json.load(jsonRead))